import { createStore } from "vuex";
import createPersistedState from 'vuex-persistedstate'
import adduser from '../router/adduser'
export default createStore({
    state: {
        isCollapse: true,
        newpath: '/app1',
        arr: 111,
        showData: adduser
    },
    getters: {

    },
    mutations: {
        changeNewpath(state, val) {
            state.newpath = val
        },
        // 添加用户
        showd(state, val) {
            state.showData.push(val)
        },
        // 删除用户
        dateleuserlist(state, val) {
            for (let index = 0; index < state.showData.length; index++) {
                if (state.showData[index].id == val) {
                    state.showData.splice(index, 1)
                }

            }

        },
        mutaeditList(state, val) {
            for (let index = 0; index < state.showData.length; index++) {
                if (state.showData[index].id == val.id) {
                    state.showData.push(val)
                }
            }
        },
        newshowData(state, val) {
            // console.log(val.newtable,val.newid);
            state.showData = val
        }
    },
    actions: {
        Acuserlist(content, val) {
            content.commit('showd', val)
        },
        // 删除信息
        Acdeleteuserlist(content, val) {
            content.commit('dateleuserlist', val)
        },
        AceditList(content, val) {
            content.commit('mutaeditList', val)
        },
    },
    modules: {

    },
    plugins: [
        createPersistedState({
            paths: ['showData']
        })
    ]
})
